| Conditions | 3 |
| Paths | 8 |
| Total Lines | 86 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** global: GLSR, site_reviews_pointers, wp, x */ |
||
| 3 | x( function() |
||
| 4 | { |
||
| 5 | var GLSR_fix = GLSR.getURLParameter( 'fix' ); |
||
| 6 | var GLSR_textarea = x( '#contentdiv > textarea' ); |
||
| 7 | |||
| 8 | if( GLSR_fix ) { |
||
| 9 | x( 'td [data-key="' + GLSR_fix + '"]').focus(); |
||
| 10 | } |
||
| 11 | |||
| 12 | if( GLSR_textarea.length ) { |
||
| 13 | GLSR.textareaResize( GLSR_textarea ); |
||
| 14 | |||
| 15 | x( document ).on( 'wp-window-resized.editor-expand', function() { |
||
| 16 | GLSR.textareaResize( GLSR_textarea ); |
||
| 17 | }); |
||
| 18 | } |
||
| 19 | |||
| 20 | x( 'form' ).on( 'change', ':input', GLSR.onFieldChange ); |
||
| 21 | x( 'form' ).on( 'click', '#clear-log', GLSR.onClearLog ); |
||
| 22 | |||
| 23 | GLSR.colorControls(); |
||
| 24 | GLSR.pinned.events(); |
||
| 25 | |||
| 26 | x.each( site_reviews_pointers.pointers, function( i, pointer ) { |
||
| 27 | GLSR.pointers( pointer ); |
||
| 28 | }); |
||
| 29 | |||
| 30 | x( document ).on( 'click', function( ev ) |
||
| 31 | { |
||
| 32 | if( !x( ev.target ).closest( '.glsr-mce' ).length ) { |
||
| 33 | GLSR.shortcode.close(); |
||
| 34 | } |
||
| 35 | }); |
||
| 36 | |||
| 37 | x( document ).on( 'click', '.glsr-mce-button', GLSR.shortcode.toggle ); |
||
| 38 | x( document ).on( 'click', '.glsr-mce-menu-item', GLSR.shortcode.trigger ); |
||
| 39 | x( document ).on( 'click', 'a.change-site-review-status', GLSR.onChangeStatus ); |
||
| 40 | |||
| 41 | // WP 4.0 - 4.2 support: toggle list table rows on small screens |
||
| 42 | x( document ).on( 'click', '.branch-4 .toggle-row, .branch-4-1 .toggle-row, .branch-4-2 .toggle-row', function() { |
||
| 43 | x( this ).closest( 'tr' ).toggleClass( 'is-expanded' ); |
||
| 44 | }); |
||
| 45 | |||
| 46 | new GLSR.search( '#glsr-search-translations', { |
||
|
|
|||
| 47 | action: 'search-translations', |
||
| 48 | onInit: function() { |
||
| 49 | this.makeSortable(); |
||
| 50 | }, |
||
| 51 | onResultClick: function( ev ) { |
||
| 52 | var result = x( ev.target ); |
||
| 53 | var entry = result.data( 'entry' ); |
||
| 54 | var template = wp.template( 'glsr-string-' + ( entry.p1 ? 'plural' : 'single' )); |
||
| 55 | entry.index = this.options.entriesEl.children().length; |
||
| 56 | entry.prefix = this.options.resultsEl.data( 'prefix' ); |
||
| 57 | if( template ) { |
||
| 58 | this.options.entriesEl.append( template( entry )); |
||
| 59 | this.options.exclude.push({ id: entry.id }); |
||
| 60 | this.options.results = this.options.results.filter( function( i, el ) { |
||
| 61 | return el !== result.get(0); |
||
| 62 | }); |
||
| 63 | } |
||
| 64 | this.setVisibility(); |
||
| 65 | }, |
||
| 66 | }); |
||
| 67 | |||
| 68 | new GLSR.search( '#glsr-search-posts', { |
||
| 69 | action: 'search-posts', |
||
| 70 | onInit: function() { |
||
| 71 | this.el.on( 'click', '.glsr-remove-button', this.onUnassign.bind( this )); |
||
| 72 | }, |
||
| 73 | onResultClick: function( ev ) { |
||
| 74 | var result = x( ev.target ); |
||
| 75 | var template = wp.template( 'glsr-assigned-post' ); |
||
| 76 | var entry = { |
||
| 77 | url: result.data( 'url' ), |
||
| 78 | title: result.text(), |
||
| 79 | }; |
||
| 80 | if( template ) { |
||
| 81 | this.el.find( 'input#assigned_to' ).val( result.data( 'id' )); |
||
| 82 | this.el.find( '.description' ).html( template( entry )); |
||
| 83 | this.el.on( 'click', '.glsr-remove-button', this.onUnassign.bind( this )); |
||
| 84 | this.reset(); |
||
| 85 | } |
||
| 86 | }, |
||
| 87 | }); |
||
| 88 | }); |
||
| 89 |